﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class SumUpCell : MonoBehaviour {

	// Use this for initialization
	public long PlayerId;
	public Image headImg;
	private Text nameTxt;
	private Text idTxt;
	private Text MarkTxt;
	private Transform Container;
	private Image Owner;
	public Sprite head ;
	public string Name = "";
	public string Mark = "0";
	public Zjh.PlayerBillInfo data;

	// Use this for initialization
	void Start () {
		InvokeRepeating ("init", 0.1f, 0f);
	}

	private void init(){
		if (data == null) {
			return;
		}

		PlayerId = data.playerId;
		Mark = data.cedit.ToString ();

		if(PlayerId == info.UserInfo.UserData.id){
			transform.GetChild (1).gameObject.SetActive (false);
		}

		headImg = transform.GetChild (2).GetComponent<Image> ();
		headImg.transform.GetChild(0).GetComponent<Image>().sprite = head;
		nameTxt = transform.GetChild (3).GetComponent<Text> ();
		idTxt = transform.GetChild (4).GetComponent<Text> ();
		Container = transform.GetChild (5);
		MarkTxt = transform.GetChild (7).GetComponent<Text> ();
		Owner = transform.GetChild (8).GetComponent<Image> ();
		nameTxt.text = Name;
		MarkTxt.text = Mark.ToString();

		if (int.Parse (Mark) < 0) {
			MarkTxt.color = Color.red;
		} else {
			MarkTxt.color = Color.red;
		}

		//idTxt.text = Name;
		idTxt.text = "ID:"+ PlayerId.ToString ();

		Container.GetChild (0).GetComponent<Text> ().text = "豹子次数:"+data.baoZiNum;
		Container.GetChild (1).GetComponent<Text> ().text = "同花顺次数:"+data.tongHuaShunNum;
		Container.GetChild (2).GetComponent<Text> ().text = "同花次数:"+data.jinHuaNum;
		Container.GetChild (3).GetComponent<Text> ().text = "顺子次数:"+data.shunZiNum;
		Container.GetChild (4).GetComponent<Text> ().text = "对子次数:"+data.duiZiNum;

		if (info.UserInfo.room.owner != PlayerId) {
			Owner.gameObject.SetActive (false);
		}
	}

	public void IsBigWiner(bool flag){
		transform.GetChild (6).gameObject.SetActive (flag);
	}

	private string GetType(string type){
		if(type == "0"){
			return "钳子";
		}else if(type == "1"){
			return  "散牌";
		}else if(type == "2"){
			return  "对子";
		}else if(type == "3"){
			return  "顺子";
		}else if(type == "4"){
			return  "同花";
		}else if(type == "5"){
			return  "同花顺";
		}else if(type == "6"){
			return  "豹子";
		}
		return "";
	}
	
	// Update is called once per frame
	void Update () {
		if (head != null) {
			if ( headImg != null ) {
				headImg.sprite = head;
			}
		}
	}
}
